
$(function() {
	Tip.emp('负责人');
	
	$("select[id^='emp_t_s']:visible").change(function() {
		var label = $("label[id^='label_emp_t']:visible");
		var a = $(this).val();
		if (a == 'emp') {
			label.html("负责人：");
		} else if (a == 'oper') {
			label.html("录入员：");
		} else if (a == 'cashier') {
			label.html("出纳：");
		}
	});
	
	$("input[id^='amount']:visible").css("width", 85);

	Tip.supplier();
	
	$("select[id^='invoice_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
	
	$("select[id^='payment_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
	
	$("select[id^='currency_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
	
	$("select[id^='account_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
	
	$("select[id^='bank_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
});

function cashier() {
	
	$("input[id^='cashier_s']:visible").autocomplete(Test.emp);
	
	_ck_default("input[id^='cashier_s']:visible", "input[id^='t_cashier']:visible");
}

function sunxy() {
	alert("sunxy...");
}

var Payment = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_add")[0];

				var body = { };
				
				body.iscustomer = form.iscustomer.value;
				body.supplier = form.supplier.value;				
				body.supplier_x = Supplier.supplier_x(form);
				
				body.type = form.type.value;
				body.name = form.name.value;
				body.amount = form.amount.value;
				body.currency = form.currency.value;
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.invoice = form.invoice.value;
				body.urgent = form.urgent.value;
				body.payment = form.payment.value;
				body.payment_x = Common.payment_x(form);
				if (!body.payment_x) {
					return false;
				}
				
				body.voucher = form.voucher.value;
				body.voucher_x = form.voucher_x.value;
				
				body.content = form.content.value;
				
				body.emp = form.emp.value;
				body.date = form.date.value;

				$(this).dialog("close");

				$.post('finance.php?do=Payment.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_add(url, title, xy);
	},
	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		$.cookie('status_', status);

		p2 = query(p2);
		$.cookie('p2', p2);
		
		var c1 = 'finance.php?do=Payment.edit&id=' + id;
		var c2 = 'finance.php?do=Payment.view&id=' + id;
				
		var cs = 'finance.php?do=Payment.status&id=' + id + p2;
		
		var a1 = ['编辑信息', 'url', 'Payment.dialog_edit_', '650x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x400'];
						
		// 付款申请
		if (status == 1) {
			var d1 = 'finance.php?do=Payment.verify&id=' + id;
			var b1 = ['审核付款', 'url', 'Payment.dialog_verify', '650x420'];
			
			var s = d1 + ", " + c1 + ", " + c2;

			return this.popup_(e, [b1, a1, a2], s);
		}
		
		// 等待付款
		if (status == 2) {
			var d1 = 'finance.php?do=Payment.begin&id=' + id;
			var b1 = ['开始付款', 'url', 'Payment.dialog_begin', '650x400'];
						
			var d2 = 'finance.php?do=Payment.finish&id=' + id;
			var b2 = ['完成付款', 'url', 'Payment.dialog_finish', '650x400'];
			
			var s = d1 + ", " + d2 + ", " + c1 + ", " + c2;

			return this.popup_(e, [b1, b2, a1, a2], s);
		}
		
		// 正在付款
		if (status == 3) {
			var d1 = 'finance.php?do=Payment.finish&id=' + id;
			var b1 = ['完成付款', 'url', 'Payment.dialog_finish', '650x400'];
			
			var s = d1 + ", " + c1 + ", " + c2;

			return this.popup_(e, [b1, a1, a2], s);
		}
		
		/*
		if (status == 4) {
			var d1 = 'finance.php?do=Payment.money&id=' + id;
			var b1 = ['付款登记', 'url', 'Payment.dialog_money', '650x400'];
			
			var s = d1 + ", " + c2;

			return this.popup_(e, [b1, a2], s);
		}*/
		
		var s = c1 + ", " + c2;

		return this.popup_(e, [a1, a2], s);
	},

	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var c1 = 'finance.php?do=Payment.upload&id=' + id;
		var a1 = ['上传附件', 'url', 'Common.dialog_upload', '600x420'];
		
		var c2 = 'finance.php?do=Payment.view&print=print&id=' + id;
		var a2 = ['打印信息', 'url', 'Common.dialog_view_', '742x508'];
		
		var c3 = 'finance.php?do=Payment.view&check=hsbc&id=' + id;
		var a3 = ['汇丰支票', 'url', 'Common.dialog_view_', '742x508'];
		
		var c4 = 'finance.php?do=Payment.view&check=icbc&id=' + id;
		var a4 = ['工行支票', 'url', 'Common.dialog_view_', '742x520'];
		
		var c5 = 'finance.php?do=Payment.copy&id=' + id;
		var a5 = ['复制信息', 'url', 'Payment.dialog_copy_', '650x400'];
		
		var ss = 'finance.php?do=Payment.ss&id=' + id;
		var bb = ['修改状态', 'url', 'Payment.dialog_ss', '400x200'];
		
		s += ", " + c1 + ", " + c2 + ", " + c3 + ", " + c4 + ", " + c5 + ", " + ss;
		
		a.push(a1);
		a.push(a2);
		a.push(a3);
		a.push(a4);
		a.push(a5);
		a.push(bb);
		
		return popup(e, a, s);
	},

	/**
	 * 修改状态
	 */
	dialog_ss: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=151', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'finance.php?do=Payment.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_edit")[0];

				var body = {};
				body.id = form.id.value;
				
				body.iscustomer = form.iscustomer.value;
				body.supplier = form.supplier.value;				
				body.supplier_x = Supplier.supplier_x(form);
				
				body.type = form.type.value;
				body.name = form.name.value;
				body.amount = form.amount.value;
				body.currency = form.currency.value;
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.invoice = form.invoice.value;
				body.urgent = form.urgent.value;
				body.payment = form.payment.value;
				body.payment_x = Common.payment_x(form);
				if (!body.payment_x) {
					return false;
				}
				
				body.voucher = form.voucher.value;
				body.voucher_x = form.voucher_x.value;
				
				body.content = form.content.value;
				body.emp = form.emp.value;
				body.date = form.date.value;

				$(this).dialog("close");

				var url = 'finance.php?do=Payment.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_edit")[0];

				var body = {};
				
				body.iscustomer = form.iscustomer.value;
				body.supplier = form.supplier.value;
				body.supplier_x = Supplier.supplier_x(form);
				
				body.type = form.type.value;
				body.name = form.name.value;
				body.amount = form.amount.value;
				body.currency = form.currency.value;
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.invoice = form.invoice.value;
				body.urgent = form.urgent.value;
				body.payment = form.payment.value;
				body.payment_x = Common.payment_x(form);
				if (!body.payment_x) {
					return false;
				}
				
				body.voucher = form.voucher.value;
				body.voucher_x = form.voucher_x.value;
				
				body.content = form.content.value;				
				body.emp = form.emp.value;
				body.date = form.date.value;

				$(this).dialog("close");

				var url = 'finance.php?do=Payment.addPost';

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},

	dialog_verify: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=151', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},		

					"不同意": function() {
						if (!confirm("确认是否审核不同意？")) {
							return false;
						}
						
						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.bank = form.bank.value;
						body.account = form.account.value;
						body.content = form.content.value;
						body.status = 9;
						
						var url = 'finance.php?do=Payment.verifyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					},
					
					"同意": function() {
						if (!confirm("确认是否同意？")) {
							return false;
						}

						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						
						body.bank = form.bank.value;
						body.account = form.account.value;
						body.content = form.content.value;
						
						body.status = 2;
						
						var url = 'finance.php?do=Payment.verifyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});	
	},

	list_start: function (url, view) {
		$.getJSON('finance.php?do=Payment.audit&item=151', function(json) {
			if (json.status == 1) {
				if (confirm("是否开始付款？")) {
					list(url, view);
				}
			} else {
				_error();
			}
		});	
	},

	dialog_begin: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=152', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},		

					"开始": function() {
						if (!confirm("确认是否开始付款？")) {
							return false;
						}
						
						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						body.bank = form.bank.value;
						body.account = form.account.value;
						body.email = form.email.value;
						body.content = form.content.value;
						
						var url = 'finance.php?do=Payment.beginPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});	
	},
	
	dialog_finish: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=152', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},		

					"完成": function() {
						if (!confirm("确认是否完成付款？")) {
							return false;
						}
						
						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						body.finish = form.finish_dd.value + " " + form.finish_tt.value;
						
						body.bank = form.bank.value;
						body.account = form.account.value;
						body.email = form.email.value;
						body.content = form.content.value;
						
						var url = 'finance.php?do=Payment.finishPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});	
	},
	
	download: function (key) {
		if (!confirm("确认是否下载？若下载，建议先另存，再打开。")) {
			return false;
		}
		
		var url = 'finance.php?do=Payment.download&key=' + key;
		jswin(url, 'save', '800x600');
		
		return true;
	},
	
	file: function (id, key) {
		if (!confirm("确认是否删除？")) {
			return false;
		}
		
		var c6 = 'finance.php?do=Payment.upload&id=' + id;
		
		var url = 'finance.php?do=Payment.file';
		var body = { };
		body.key = key;
		
		$.post(url, body, function(data) {
			// alert(data);
			$.get(c6, function(data) {
				$('#dialog_edit').html(data);
			});
		});
		
		return true;
	},
	
	dialog_money: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=152', function(json) {
			if (json.status == 1) {
				$('#dialog_add').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},		

					"登记": function() {
						var form = $("#form_add")[0];
						
						if (form.account.value == '-') {
							alert("请选择帐号！");
							return false;
						}
						
						if (form.currency.value == '-') {
							alert("请选择币种！");
							return false;
						}
						
						if (!confirm("确认是否登记？")) {
							return false;
						}
												
						var body = {};
						body.id = form.id.value;
						
						body.account = form.account.value;
						body.name = form.name.value;				
						body.content = form.content.value;

						body.date = form.date.value;
						body.currency = form.currency.value;
						body.income = form.income.value;				
						body.out = form.out.value;
						
						var url = 'finance.php?do=Payment.moneyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							// $(result).html(data);
							alert("登记成功！");
						});
					}
				});

				dialog_add(url, title, xy);
			} else {
				_error();
			}
		});	
	},
	
	popup_all: function (e, p2) {
		p2 = query(p2);
		$.cookie('p2', p2);
		
		this.bank(e);
	},
	
	abc: function (json, e) {

		var p2 = $.cookie('p2');
		// alert(p2);
		
		var c1 = 'finance.php?do=Payment.delete' + p2;
		var c3 = 'finance.php?do=Payment.batch_verify';
		
		var a1 = ['删除信息', 'url', 'Common.list_delete'];
		var a3 = ['审核信息', 'url', 'Payment.dialog_batch_verify', '800x450'];
		
		var s = c1 + ", " + c3;
		var a = [a1, a3];
		
		for (i = 0; i < json.length; i++) {
			// alert(json[i].id + ", " + json[i].bank + ", " + json[i].type);
			
			if (json[i].bank == '招商银行' && json[i].type == '1') {
				var c2 = 'finance.php?do=Payment.txt' + p2;
				var a2 = ['个人招行', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '招商银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.txt&bank=cmb' + p2;
				var a2 = ['公司招行', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '广发银行' && json[i].type == '1') {
				var c2 = 'finance.php?do=Payment.xls_cgb' + p2;
				var a2 = ['个人广发', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '中国工商银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.xls_icbc' + p2;
				var a2 = ['工行Excel', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '中国民生银行' && json[i].type == '1') {
				var c2 = 'finance.php?do=Payment.txt&bank=cmbc' + p2;
				var a2 = ['个人民生', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '东莞农村商业银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.xls_drc' + p2;
				var a2 = ['公司东莞农商', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '中国民生银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.txt&bank=cmbc' + p2;
				var a2 = ['公司民生', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '平安银行' && json[i].type == '1') {
				var c2 = 'finance.php?do=Payment.xls_pa' + p2;
				var a2 = ['个人平安', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '兴业银行' && json[i].type == '1') {
				var c2 = 'finance.php?do=Payment.txt&bank=cib' + p2;
				var a2 = ['个人兴业', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '兴业银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.txt&bank=cib_c' + p2;
				var a2 = ['公司兴业', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '北京银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.bj' + p2;
				var a2 = ['北京银行', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '中信银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.txt&bank=citic' + p2;
				var a2 = ['中信银行', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '中国银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.txt&bank=boc' + p2;
				var a2 = ['中国银行', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
			
			if (json[i].bank == '中国建设银行' && json[i].type == '2') {
				var c2 = 'finance.php?do=Payment.txt&bank=ccb' + p2;
				var a2 = ['中国建设银行', 'url', 'Common.dialog_txt', '650x400'];
				
				s += ", " + c2;
				a.push(a2);
			}
		}
		
		var c4 = 'finance.php?do=Payment.batch_begin';
		var c5 = 'finance.php?do=Payment.batch_finish';
		var c6 = 'finance.php?do=Payment.batch_type';
		
		var c9 = 'finance.php?do=Payment.xls' + p2;	
		
		var a4 = ['开始付款', 'url', 'Payment.dialog_batch_begin', '800x450'];
		var a5 = ['完成付款', 'url', 'Payment.dialog_batch_finish', '800x450'];
		var a6 = ['更新类型', 'url', 'Payment.dialog_batch_type', '800x450'];
				
		var a9 = ['导出Excel', 'url', 'jswin', '1024x768'];
		
		s += ", " + c4 + ", " + c5 + ", " + c6 + ", " + c9;
		
		a.push(a4);
		a.push(a5);
		a.push(a6);
		a.push(a9);
		
		return popup(e, a, s);
	},
	
	bank: function (e) {
		var body = { };
		body.service = 4;
		
		$.getJSON('emp.php?do=BankMy.ajax_my', body, function(json) {
			// alert(e);
			Payment.abc(json, e);
		});
	},
		
	dialog_batch_verify: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=151', function(json) {
			if (json.status == 1) {			
				var c = new Array();
				$("input[name^='c_1_']").each(function() {
					if ($(this).attr("checked")) {
						var s = encodeURIComponent(this.name) + "=" + encodeURIComponent($(this).val());
						c.push(s);
					}
				});
				
				var body = c.join("&");
				
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},		

					"不同意": function() {
						if (!confirm("确认是否审核不通过？")) {
							return false;
						}
						
						var cc = Payment._cc();

						var form = $("#form_edit")[0];
						
						var body = {};
						body.cc = cc;
						body.account = form.account.value;
						body.content = form.content.value;
						body.status = 9;
						
						var url = 'finance.php?do=Payment.batch_verifyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					},
					
					"同意": function() {
						if (!confirm("确认是否同意付款？")) {
							return false;
						}
						
						var cc = Payment._cc();

						var form = $("#form_edit")[0];
						
						var body = {};
						body.cc = cc;
						body.content = form.content.value;					
						body.status = 2;
						
						var url = 'finance.php?do=Payment.batch_verifyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				var view = '#dialog_edit';
				$.get(url, body, function(data) {
					$(view).html(data);
				});

				var regex = /^(\d+)(x)(\d+)$/;
				if (regex.test(xy)) {
					var cc = xy.split("x");
					var width = parseInt(cc[0]);
					var height = parseInt(cc[1]);
					$(view).dialog('option', 'height', height);
				} else {
					var width = parseInt(xy);
				}

				$(view).dialog('option', 'title', title);
				$(view).dialog('option', 'width', width);
				$(view).dialog('open');
			} else {
				_error();
			}
		});	
	},
	
	dialog_batch_begin: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=152', function(json) {
			if (json.status == 1) {			
				var c = new Array();
				$("input[name^='c_2_']").each(function() {
					if ($(this).attr("checked")) {
						var s = encodeURIComponent(this.name) + "=" + encodeURIComponent($(this).val());
						c.push(s);
					}
				});
				
				var body = c.join("&");
				
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},					
					
					"开始": function() {
						if (!confirm("确认是否开始付款？")) {
							return false;
						}
						
						var cc = Payment._cc();

						var form = $("#form_edit")[0];
						
						var body = {};
						body.cc = cc;
						body.bank = form.bank.value;
						body.account = form.account.value;
						body.content = form.content.value;					
						body.status = 3;
						
						var url = 'finance.php?do=Payment.batch_beginPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				var view = '#dialog_edit';
				$.get(url, body, function(data) {
					$(view).html(data);
				});

				var regex = /^(\d+)(x)(\d+)$/;
				if (regex.test(xy)) {
					var cc = xy.split("x");
					var width = parseInt(cc[0]);
					var height = parseInt(cc[1]);
					$(view).dialog('option', 'height', height);
				} else {
					var width = parseInt(xy);
				}

				$(view).dialog('option', 'title', title);
				$(view).dialog('option', 'width', width);
				$(view).dialog('open');
			} else {
				_error();
			}
		});	
	},
	
	dialog_batch_finish: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=152', function(json) {
			if (json.status == 1) {			
				var c = new Array();
				$("input[name^='c_2_']").each(function() {
					if ($(this).attr("checked")) {
						var s = encodeURIComponent(this.name) + "=" + encodeURIComponent($(this).val());
						c.push(s);
					}
				});
				
				$("input[name^='c_3_']").each(function() {
					if ($(this).attr("checked")) {
						var s = encodeURIComponent(this.name) + "=" + encodeURIComponent($(this).val());
						c.push(s);
					}
				});
				
				var body = c.join("&");
				
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},					
					
					"完成": function() {
						if (!confirm("确认是否完成付款？")) {
							return false;
						}
						
						var cc = Payment._cc();

						var form = $("#form_edit")[0];
						
						var body = {};
						body.cc = cc;
						body.finish = form.finish_dd.value + " " + form.finish_tt.value;
						
						body.bank = form.bank.value;
						body.account = form.account.value;
						body.email = form.email.value;
						body.content = form.content.value;
						
						var url = 'finance.php?do=Payment.batch_finishPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				var view = '#dialog_edit';
				$.get(url, body, function(data) {
					$(view).html(data);
				});

				var regex = /^(\d+)(x)(\d+)$/;
				if (regex.test(xy)) {
					var cc = xy.split("x");
					var width = parseInt(cc[0]);
					var height = parseInt(cc[1]);
					$(view).dialog('option', 'height', height);
				} else {
					var width = parseInt(xy);
				}

				$(view).dialog('option', 'title', title);
				$(view).dialog('option', 'width', width);
				$(view).dialog('open');
			} else {
				_error();
			}
		});	
	},
	
	dialog_batch_type: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Payment.audit&item=152', function(json) {
			if (json.status == 1) {			
				var c = new Array();
				$("input[name^='c_']").each(function() {
					if ($(this).attr("checked")) {
						var s = encodeURIComponent(this.name) + "=" + encodeURIComponent($(this).val());
						c.push(s);
					}
				});
				
				var body = c.join("&");
				
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},
					
					"提交": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
						
						var cc = ExpenseLog._cc();

						var form = $("#form_edit")[0];
						
						var body = {};
						body.cc = cc;
						body.type = form.type.value;
						body.content = form.content.value;
						
						var url = 'finance.php?do=Payment.batch_typePost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
						
						$(this).dialog("close");

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				var view = '#dialog_edit';
				$.get(url, body, function(data) {
					$(view).html(data);
				});

				var regex = /^(\d+)(x)(\d+)$/;
				if (regex.test(xy)) {
					var cc = xy.split("x");
					var width = parseInt(cc[0]);
					var height = parseInt(cc[1]);
					$(view).dialog('option', 'height', height);
				} else {
					var width = parseInt(xy);
				}

				$(view).dialog('option', 'title', title);
				$(view).dialog('option', 'width', width);
				$(view).dialog('open');
			} else {
				_error();
			}
		});	
	},
	
	_cc: function () {
		var c = new Array();
		$("input[name^='b_']").each(function() {
			if ($(this).attr("checked")) {
				c.push($(this).val());
			}
		});
		
		return c;
	}
};
